﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using Lamex.Base;
using Lamex.Library;
using Lamex.Library.UserCotrolUI;
using Lamex.mMES.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.mMES.Common
{
    public class LogicHelper
    {
        static System.Timers.Timer t3 = null;//30分钟后定时器
        static string[] arryError = { "MS", "QC", "WS", "CH", "MT", "EQ" };
        static string[] arryErrorNOQC = { "MS", "WS", "CH", "MT", "EQ" };
        static string[] arryErrorNOEQ = { "MS", "WS", "CH", "MT" };
        static string[] arryList = { "MES_QCSA", "MES_QCPA", "MES_QCDA", "MES_QCMA" };
        static string[] arryOrderNumber = { "DK", "PL", "PN", "MG" };
        static string[] arryPressStation = { "WS_S06", "WS_S08", "WS_S13", "WS_S16", "WS_S17", "WS_S18", "WS_S19" };
        static int iBeForComSum = 0;
        static int iAfterComSum = 0;
        static int iStanderItime = 200;
        static int maxStandertime = 220;
        static int minStandertime = 180;
        static int standertime = 200;
        static int productTime = 212;
        static double iCycletime = 200;
        static double iLimitime = 0.1;
        static string UserNames = "";

        /// <summary>
        /// 扫描逻辑
        /// </summary>
        /// <param name="str_barcode">条码号</param>
        /// <param name="dtUI">显示临时表</param>
        /// <param name="strScanerQty">数量</param>
        /// <param name="strStarTime">开始时间-每次绿色灯亮重设该时间</param>
        /// <param name="UserName">登录名</param>
        /// <param name="PortName_COM">COM号</param>
        /// <param name="firstTime">当天最早时间</param>
        /// <param name="lastTime">当天最晚时间</param>
        /// <param name="lb_Name1">科文图片-姓名</param>
        /// <param name="lb_Name2">组长图片-姓名</param>
        /// <param name="LabelControl1">人员或产品信息</param>
        /// <param name="picTop1">科文图片</param>
        /// <param name="picTop2">组长图片</param>
        /// <param name="picTop3">人员信息图片</param>
        /// <param name="lblInfo_4">信息显示4</param>
        /// <param name="lblStatus">状态提示</param>
        /// <param name="LampGreen">颜色灯</param>
        /// <param name="lblInfo_1">信息显示1</param>
        /// <param name="lblInfo_2">信息显示2</param>
        /// <param name="lblInfo_3">信息显示3</param>
        /// <param name="timer1">定时器</param>
        /// <param name="gcMid_B"></param>
        /// <param name="gridView1"></param>
        /// <param name="strStarTime1">开始时间-每次绿色灯亮重设该时间-需返回给前台</param>
        /// <returns></returns>
        public static String Logic_Scan(string str_barcode, DataTable dtUI, string strScanerQty, string strStarTime, string UserName, string PortName_COM, string

firstTime, string lastTime,
            LabelControl lb_Name1, LabelControl lb_Name2, LabelControl LabelControl1, PictureBox picTop1, PictureBox picTop2, PictureBox picTop3,
            LabelControl lblInfo_4, LabelControl lblStatus, FrmLampControlUI LampGreen, LabelControl lblInfo_1, LabelControl lblInfo_2, LabelControl lblInfo_3, Timer

timer1,
            GridControl gcMid_B, GridView gridView1, out string strStarTime1)
        {
            string result = "";
            strStarTime1 = strStarTime;
            UserNames = UserName;
            try
            {
                //空或长度不够，直接返回
                if (string.IsNullOrEmpty(str_barcode) || str_barcode.Length < 6) return result;

                DataTable dt = BaseBuildSql.GetDataTableBySql("select * from [dbo].[HR_Process_CycleTime] where PRODUCT='" + str_barcode + "'");

                if (dt.Rows.Count != 0)
                {
                    iCycletime = double.Parse(dt.Rows[0]["CYCLETIME"].ToString());
                    double sums_Max = iCycletime + double.Parse(dt.Rows[0]["LIMIT_RATE"].ToString()) * double.Parse(dt.Rows[0]["CYCLETIME"].ToString());
                    double sum_Min = iCycletime - double.Parse(dt.Rows[0]["LIMIT_RATE"].ToString()) * double.Parse(dt.Rows[0]["CYCLETIME"].ToString());
                    maxStandertime = Convert.ToInt32(sums_Max);
                    minStandertime = Convert.ToInt32(sum_Min);

                    iStanderItime = Convert.ToInt32((iCycletime).ToString());
                    productTime = Convert.ToInt32(dt.Rows[0]["CHANGEOVER_TIME"].ToString());
                }
                //异常条码表
                DataTable dtWorkCode = Common.GetDataTable.GetWork_Barcode();
                if (str_barcode.Substring(0, 3) == "MES" || str_barcode.Substring(0, 3) == "LMX" ||
                    Common.GetDataTable.GetPart_Detailed().Select("Order_Number='" + str_barcode + "'").Length > 0)
                {
                    //得到最后一个条码
                    DataTable dt_LastBarCode = Common.GetDataTable.GetLastBarCode_StationName(UserName);
                    //得到当天不是撤销标识的最后两个条码
                    DataTable dt_S08_1 = Common.GetDataTable.GetNoCancel_Top2(firstTime, UserName);
                    //得到当天不是撤销标识且不是MES_MG11111的最后两个条码
                    DataTable dt_S08_2 = Common.GetDataTable.GetNoCancelNoMG_Top2(firstTime, UserName);
                    //得到当天MES_MG00000的记录
                    DataTable dt_MG00000 = Common.GetDataTable.GetHR_Scan_Record_MG00000(firstTime, lastTime, UserName);
                    //转换得到扫描人和工位对应姓名
                    string Location_Code = "", Scanner_No = "";
                    Common.ScanRecordHelper.GetHRInfo(Common.GetDataTable.GetHR_Station_Info(), UserName, UserName + "_" + PortName_COM, str_barcode, out 
Location_Code, out Scanner_No);
                    //1、【MES_MG00000】上一码下线码MES_MG99999或未开线码MES_MG88888  
                    if (str_barcode == "MES_MG00000")
                    {
                        if (dt_LastBarCode.Rows.Count <= 0 ||
                            dt_LastBarCode.Rows[0]["BARCODE"].ToString() == "MES_MG99999" ||
                            dt_LastBarCode.Rows[0]["BARCODE"].ToString() == "MES_MG88888")
                        {
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        }

                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }
                    //2、【MES_MG88888】上一码下线码MES_MG99999
                    if (str_barcode == "MES_MG88888")
                    {
                        if (dt_LastBarCode.Rows[0]["BARCODE"].ToString() == "MES_MG99999")
                        {
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //3、【MES_MG99999】下线码
                    if (str_barcode == "MES_MG99999")
                    {
                        //当天当前工作站无记录时可以扫入
                        if (dt_S08_2.Rows.Count <= 0)
                        {
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                            Common.LampHelper.endTime(timer1);
                        }
                        string strTemp = dt_S08_2.Rows[0]["BARCODE"].ToString();
                        if (dtWorkCode.Select("BARCODE_SN='" + strTemp + "'").Length > 0)
                        {
                            string strColor = dtWorkCode.Select("BARCODE_SN='" + strTemp + "'").CopyToDataTable().Rows[0]["LIGHT_STATE"].ToString();
                            if (strColor == "Green")
                            {
                                Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                                Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                                Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                Common.LampHelper.endTime(timer1);
                            }
                            else
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                        }
                        // update by Bill 20191216 robin要求增加此逻辑判断
                        else if (strTemp.Contains("PD") || strTemp.Contains("DK") || strTemp.Contains("PN") || strTemp.Contains("PL"))
                        {
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                            Common.LampHelper.endTime(timer1);
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //4、【MES_MG11111】撤销码
                    if (str_barcode == "MES_MG11111")
                    {
                        //不可以连续扫描两次撤销码
                        if (dt_S08_1.Rows[0]["BARCODE"].ToString() == "MES_MG11111")
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                        //dt_S08_2最少有一条记录
                        if (dt_S08_2.Rows.Count == 1)
                        {
                            if (dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG00000")
                            {
                                Common.ScanRecordHelper.Update(dt_S08_2.Rows[0]["BARCODE"].ToString(), dt_S08_2.Rows[0]["SCAN_TIME"].ToString());
                                Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                                Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                                Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                Common.LampHelper.endTime(timer1);
                                Common.LampHelper.StopLamp(LampGreen);
                            }
                        }
                        else
                        {
                            //更新撤销标识
                            Common.ScanRecordHelper.Update(dt_S08_2.Rows[0]["BARCODE"].ToString(), dt_S08_2.Rows[0]["SCAN_TIME"].ToString());
                            //写入数据库
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(dt_S08_2.Rows[1]["BARCODE"].ToString(), UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2,

picTop3, lblInfo_4, lblStatus, LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        }
                    }

                    //5、产品码【MES_PD_S08_Array】
                    if (str_barcode.Substring(0, 6) == "MES_PD")
                    {
                        RefreshList.InitLoad(UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, str_barcode);
                        if (arryPressStation.Contains(UserName) && dt_MG00000.Rows.Count > 0)
                        {
                            if (dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG00000" ||
                                 dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_CH00001")
                            {
                                Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                                Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                                strStarTime1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                                Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                Common.LogicHelper.Logic_ReceiveData(dtUI, firstTime, lastTime, UserName, strStarTime1, lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4,

gcMid_B, gridView1);
                            }
                            else
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }

                    }

                    //6、停线报告
                    if (arryError.Contains(str_barcode.Substring(4, 2)) &&
                       str_barcode.Substring(6, 5) == "00000")
                    {

                        if (dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG99999" ||
                            dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG00000" ||
                        dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG88888" ||
                        (arryError.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(4, 2)) &&
                        dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(6, 5) == "00000"))
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                        //写入数据库 
                        Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, str_barcode.Substring(4, 2));
                        Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                        //result = "special_1";
                        //return result;
                        Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                        Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        Task.Run(() => SendMailerCheck(str_barcode));
                        Common.LogicHelper.Logic_ReceiveData(dtUI, firstTime, lastTime, UserName, strStarTime, lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4, gcMid_B,

gridView1);
                    }

                    //7、不停线报告
                    if (arryError.Contains(str_barcode.Substring(4, 2)) &&
                      str_barcode.Substring(6, 5) == "90000")
                    {
                        //写入数据库 
                        Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, "");
                        Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                        //result = "special_1";
                        //return result;
                        Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                        Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        Task.Run(() => SendMailerCheck(str_barcode));
                        Common.LogicHelper.Logic_ReceiveData(dtUI, firstTime, lastTime, UserName, strStarTime, lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4, gcMid_B,

gridView1);

                    }

                    //8、确认人
                    if (str_barcode.Substring(0, 6) == "LMX_TX")
                    {
                        if (arryError.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(4, 2))
                                && dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(6, 5) == "00000")
                        {
                            DataTable dtWorks = Common.GetDataTable.GetWorksInfo(str_barcode);
                            if (dtWorks.Rows.Count > 0)
                            {
                                string[] arryCode = dtWorks.Rows[0]["OPRATION_CODE"].ToString().Split(';');
                                if (arryCode.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(4, 2)))
                                {
                                    DateTime t1 = Convert.ToDateTime(dt_S08_2.Rows[0]["SCAN_TIME"].ToString());//前一个条码时间
                                    DateTime t2 = DateTime.Now;//当前时间
                                    TimeSpan t3 = t2 - t1;//时间差
                                    Common.ScanRecordHelper.Insert("", str_barcode, 0, Math.Ceiling(t3.TotalSeconds), t2, Scanner_No, Location_Code, UserName,

dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(4, 2));
                                    Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");

                                    Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4,

lblStatus, LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                    Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                    Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】扫入成功！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                }
                                else
                                {
                                    Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】无权限操作！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                }
                            }
                            else
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //9、异常码 生产异常 当前码存在MS、WS、CH、MT中有任一种
                    if (arryErrorNOEQ.Contains(str_barcode.Substring(4, 2)) &&
                         str_barcode.Substring(6, 5) != "00000" &&
                         str_barcode.Substring(6, 5) != "90000" &&
                        IsInt(str_barcode.Substring(6, 5)))
                    {
                        //前一码必须为LMX_TX*****
                        if (dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 6) == "LMX_TX")
                        {
                            //必须为同类型才可以扫描
                            if (str_barcode.Substring(0, 6) != (dt_S08_2.Rows[1]["BARCODE"].ToString().Substring(0, 6)))
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                            //写入数据库
                            DateTime t1 = Convert.ToDateTime(dt_S08_2.Rows[0]["SCAN_TIME"].ToString());//前一个条码时间
                            DateTime t2 = DateTime.Now;//当前时间
                            TimeSpan t3 = t2 - t1;//时间差
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, Math.Ceiling(t3.TotalSeconds), t2, Scanner_No, Location_Code, UserName,

str_barcode.Substring(4, 2));
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //10、【EQCL】
                    if (str_barcode.Substring(0, 8) == "MES_EQCL")
                    {
                        if (dt_S08_2.Rows[1]["BARCODE"].ToString() == "MES_EQ00000")
                        {
                            if (dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 6) == "LMX_TX")
                            {
                                //写入数据库 
                                Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, str_barcode.Substring(4, 2));
                                Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                                Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                Common.LogicHelper.Logic_ReceiveData(dtUI, firstTime, lastTime, UserName, strStarTime, lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4,

gcMid_B, gridView1);
                            }
                            else
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //11、【MES_EQ00001】
                    if (str_barcode.Substring(0, 6) == "MES_EQ" &&
                       str_barcode.Substring(6, 5) != "00000" &&
                       str_barcode.Substring(6, 5) != "90000" &&
                        IsInt(str_barcode.Substring(6, 5)))
                    {
                        if (dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 8) == "MES_EQCL")
                        {
                            DateTime t1 = Convert.ToDateTime(dt_S08_2.Rows[1]["SCAN_TIME"].ToString());//上上一个条码时间
                            DateTime t2 = DateTime.Now;//当前时间
                            TimeSpan t3 = t2 - t1;//时间差
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, Math.Ceiling(t3.TotalSeconds), t2, Scanner_No, Location_Code, UserName,

str_barcode.Substring(4, 2));
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                            Common.LogicHelper.Logic_ReceiveData(dtUI, firstTime, lastTime, UserName, strStarTime, lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4, gcMid_B,

gridView1);
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //12、QC
                    if (arryList.Contains(str_barcode.Substring(0, 8)))
                    {
                        //前一码必须为LMX_TX*****
                        if (dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 6) == "LMX_TX" &&
                            dt_S08_2.Rows[1]["BARCODE"].ToString() == "MES_QC00000")
                        {
                            //必须为同类型才可以扫描
                            // if (str_barcode.Substring(4, 2) != (dt_S08_2.Rows[1]["BARCODE"].ToString().Substring(4, 2)))
                            if (UserName.Substring(3, 1) != str_barcode.Substring(6, 1))
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                            //写入数据库                            
                            Common.ScanRecordHelper.Insert("", str_barcode, 0, 0, DateTime.Now, Scanner_No, Location_Code, UserName, str_barcode.Substring(4, 2));
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, 0, Location_Code, "");
                            //result = "special_2";
                            //return result;
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                            Task.Run(() => SendMailerCheck(str_barcode));
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }
                    //13、加工产品（DK、DKSJ\...）
                    if (arryOrderNumber.Contains(str_barcode.Substring(0, 2)))
                    {
                        if (dt_MG00000.Rows.Count > 0)
                        {
                            if (dt_S08_2.Rows[0]["BARCODE"].ToString() == "MES_MG00000" ||
                                arryOrderNumber.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 2)) ||
                               (arryError.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(4, 2)) &&
                               dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(6, 5) != "00000") &&
                               IsInt(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(6, 5)))
                            {
                                if (strScanerQty.Trim().Length <= 0)
                                {
                                    Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】请先输入扫描数量！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);

                                }
                                DataTable dt_Order_Number = Common.GetDataTable.GetOrder_Number_Time(firstTime, lastTime, UserName);
                                DateTime t1 = Convert.ToDateTime(dt_Order_Number.Rows[0]["SCAN_TIME"].ToString());//前一个条码时间
                                DateTime t2 = DateTime.Now;//当前时间
                                TimeSpan t3 = t2 - t1;//时间差
                                Common.ScanRecordHelper.Insert("", str_barcode, Convert.ToInt32(strScanerQty), Math.Ceiling((t3.TotalSeconds) -

Common.ScanRecordHelper.SCAN_TIME_LENGTH(firstTime, lastTime, UserName)), t2, Scanner_No, Location_Code, UserName, "");
                                Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, Convert.ToInt32(strScanerQty), Location_Code, "");
                                Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                                Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                                Common.LampHelper.StopLamp(LampGreen);
                                Common.LampHelper.StartLamp("Green", lblStatus, LampGreen);
                                Common.LampHelper.StartTime(timer1);
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】扫入成功！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);

                            }
                            else
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                                #region 写入Error_Log表
                                string strError = "";
                                if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                                {
                                    strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                                }
                                Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                                #endregion
                            }
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }

                    //14 【MES_QC】
                    if (str_barcode.Substring(0, 6) == "MES_QC" &&
                        str_barcode.Substring(6, 5) != "90000")
                    {
                        //前一码包含arryList(MES_QCSA、MES_QCPA、MES_QCDA、MES_QCMA)
                        if (arryList.Contains(dt_S08_2.Rows[0]["BARCODE"].ToString().Substring(0, 8)))
                        {
                            //写入数据库
                            DateTime t1 = Convert.ToDateTime(dt_S08_2.Rows[1]["SCAN_TIME"].ToString());//前一个条码时间
                            DateTime t2 = DateTime.Now;//当前时间
                            TimeSpan t3 = t2 - t1;//时间差
                            if (strScanerQty.Trim().Length <= 0)
                            {
                                Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】请先输入扫描数量！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            }
                            Common.ScanRecordHelper.Insert("", str_barcode, Convert.ToInt32(strScanerQty), Math.Ceiling(t3.TotalSeconds), t2, Scanner_No,

Location_Code, UserName, str_barcode.Substring(4, 2));
                            Common.ScanRecordHelper.Insert_GridControl(dtUI, str_barcode, Scanner_No, Convert.ToInt32(strScanerQty), Location_Code, "");
                            //result = "special_2";
                            //return result;
                            Common.LampHelper.ChargeLamp(str_barcode, UserName, lb_Name1, lb_Name2, LabelControl1, picTop1, picTop2, picTop3, lblInfo_4, lblStatus,

LampGreen, lblInfo_1, lblInfo_2, lblInfo_3, timer1);
                            Common.ShowHelper.GetDisplayInfo(dtUI, gcMid_B, gridView1);
                            Task.Run(() => SendMailerCheck(str_barcode));
                        }
                        else
                        {
                            Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                            #region 写入Error_Log表
                            string strError = "";
                            if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                            {
                                strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                            }
                            Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                            #endregion
                        }
                    }
                }
                else
                {
                    Common.ShowHelper.ShowAllInfo("【" + str_barcode + "】为非法码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                    #region 写入Error_Log表
                    string strError = "";
                    if (dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").Length > 0)
                    {
                        strError = dtWorkCode.Select("BARCODE_SN='" + str_barcode + "'").CopyToDataTable().Rows[0]["BARCODE_DESC"].ToString();
                    }
                    Common.ScanRecordHelper.Insert_Error(str_barcode, strError, UserName, DateTime.Now);
                    #endregion
                }
                return result;
            }
            catch
            {
                return result;
            }

        }

        public static void Logic_ReceiveData(DataTable dtUI, string firstTime, string lastTime, string UserName, string strStarTime,
            LabelControl lblInfo_1, LabelControl lblInfo_2, LabelControl lblInfo_3, LabelControl lblInfo_4, GridControl gcMid_B, GridView gridView1)
        {
            try
            {
                //得到当天MES_MG00000的记录
                DataTable dt_MG00000 = Common.GetDataTable.GetHR_Scan_Record_MG00000(firstTime, lastTime, UserName);
                if (dt_MG00000.Rows.Count <= 0)
                {
                    Common.ShowHelper.ShowAllInfo("未检测到开线码,请按流程扫描开线码！", lblInfo_1, lblInfo_2, lblInfo_3, lblInfo_4);
                    #region 写入Error_Log表
                    string strError = "未检测到有开线码,请按流程扫描开线码";
                    Common.ScanRecordHelper.Insert_Error("", strError, UserName, DateTime.Now);
                    #endregion
                    return;
                }
                string sql_ST_S08_Receive_Data = @"select NOId,ngNo,writetime from  [Edgeband_Program].[dbo].[ST_S08_Receive_Data] 
 where NOId not in(select NOID from [LamexMESManager].[dbo].[HR_Scan_Record] where NOID is not null)
and writetime>'" + strStarTime + "' and startIndex != 2 and wordtime != 0 and  station_name='" + UserName + "' ";
                DataTable dt = BaseBuildSql.GetDataTableBySql(sql_ST_S08_Receive_Data);
                DataTable dtNew = Common.GetTable.GetTable_Scan_Record();//动态保存扫描记录表
                string strPLC = "PLC";
                string strBarCode_EN = "刷新成功！";
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string strLOCATION_CODE = "";

                        switch (dt.Rows[i]["ngNo"].ToString())
                        {
                            case "1":
                                strLOCATION_CODE = strPLC + "_1";
                                break;
                            case "2":
                                strLOCATION_CODE = strPLC + "_2";
                                break;
                            case "3":
                                strLOCATION_CODE = strPLC + "_3";
                                break;
                            case "4":
                                strLOCATION_CODE = strPLC + "_4";
                                break;
                            case "5":
                                strLOCATION_CODE = strPLC + "_5";
                                break;
                            case "6":
                                strLOCATION_CODE = strPLC + "_6";
                                break;
                            case "7":
                                strLOCATION_CODE = strPLC + "_7";
                                break;
                        }

                        string Location_Code = "", Scanner_No = "";
                        Common.ScanRecordHelper.GetHRInfo(Common.GetDataTable.GetHR_Station_Info(), UserName, strLOCATION_CODE, "", out Location_Code, out Scanner_No);
                        //写入扫描记录表                    
                        Common.ScanRecordHelper.Insert(dt.Rows[i]["NOId"].ToString(), Convert.ToDateTime(dt.Rows[i]["writetime"]).ToString("yyyyMMddHHmmssfff"), 1, 0,

DateTime.Now, Scanner_No, Location_Code, UserName, "");
                        //写入UI临时显示表
                        Common.ScanRecordHelper.Insert_GridControl(dtUI, Convert.ToDateTime(dt.Rows[i]["writetime"]).ToString("yyyyMMddHHmmssfff"), Scanner_No, 1,

Location_Code, strLOCATION_CODE + ":" + strBarCode_EN);
                        if (dtUI.Rows.Count > 0)
                        {

                            DataView dv = dtUI.DefaultView;
                            dv.Sort = "SCAN_TIME Desc";
                            dtUI = dv.ToTable();
                            gcMid_B.DataSource = dtUI;
                            gridView1.BestFitColumns();
                            gridView1.OptionsView.ColumnAutoWidth = false;


                            //实时显示扫描状态
                            DataTable dtTop4 = DtSelectTop(4, dtUI);

                            if (dtTop4.Rows.Count == 1)
                            {
                                lblInfo_4.Text = dtTop4.Rows[0]["BARCODE_CN"].ToString();
                            }
                            else if (dtTop4.Rows.Count == 2)
                            {
                                lblInfo_4.Text = dtTop4.Rows[0]["BARCODE_CN"].ToString();
                                lblInfo_3.Text = dtTop4.Rows[1]["BARCODE_CN"].ToString();
                            }
                            else if (dtTop4.Rows.Count == 3)
                            {
                                lblInfo_4.Text = dtTop4.Rows[0]["BARCODE_CN"].ToString();
                                lblInfo_3.Text = dtTop4.Rows[1]["BARCODE_CN"].ToString();
                                lblInfo_2.Text = dtTop4.Rows[2]["BARCODE_CN"].ToString();
                            }
                            else
                            {
                                lblInfo_4.Text = dtTop4.Rows[0]["BARCODE_CN"].ToString();
                                lblInfo_3.Text = dtTop4.Rows[1]["BARCODE_CN"].ToString();
                                lblInfo_2.Text = dtTop4.Rows[2]["BARCODE_CN"].ToString();
                                lblInfo_1.Text = dtTop4.Rows[3]["BARCODE_CN"].ToString();
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);
            }
        }
        // 正则表达式检测是否为数字
        public static bool IsInt(string value)
        {
            return Regex.IsMatch(value, @"^[0-9]*$");
        }
        public static DataTable DtSelectTop(int TopItem, DataTable oDT)
        {
            if (oDT.Rows.Count < TopItem) return oDT;

            DataTable NewTable = oDT.Clone();
            DataRow[] rows = oDT.Select("1=1", "SCAN_TIME Desc");
            for (int i = 0; i < TopItem; i++)
            {
                NewTable.ImportRow((DataRow)rows[i]);
            }
            return NewTable;
        }

        public static void SendMailerCheck(string Barcode)
        {
            try
            {
                if (Common.MailHelper.SendExpMail(UserNames, UserNames, Barcode))
                {
                    t3 = new System.Timers.Timer(5000 * 12 * 30); //5000 * 12 * 30
                    t3.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp3);
                    t3.AutoReset = true;
                    t3.Enabled = true;
                    t3.Start();
                }
                else
                {
                    if (Barcode.Substring(0, 3) == "MES")
                    {
                        if (t3 != null)
                            t3.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message + "126");
            }
        }
        public static void Timer_TimesUp3(object sender, System.Timers.ElapsedEventArgs e)
        {
            Common.MailHelper.AferSendExpMail(UserNames, UserNames, t3);
        }
    }
}
